<template>
  <div class="market-detail">
    <PageTemplate>
      <div slot="content">
        <TitleBack :title="title"></TitleBack>
        <PageEditCollapse :is-search="false" :default-collapse="true">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 200px;">{{$t('cm.baseinfo')}}</div>
          </div>
          <div>
            <!-- 高级搜索具体内容 -->
            <el-form
              :model="marketInfo"
              label-position="right"
              label-width="150px"
              class="page-edit-colllapse-form"
              ref="marketInfo"
            >
              <el-row>
                <el-col :span="8">
                  <el-form-item label="项目名称" prop="marketName" required>
                    <span>{{marketInfo.marketName}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="客户名称" prop="customerName" required>
                    <span>{{marketInfo.customerName}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目类型" prop="projectType" required>
                    <span>{{marketInfo.projectType}}</span>
                  </el-form-item>
                </el-col>
                 <el-col :span="8">
                  <el-form-item label="客户类型" prop="customerType" required>
                    <span>{{marketInfo.customerType}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="预计金额" prop="estimateAmount">
                    <span>{{marketInfo.estimateAmount}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目区域" prop="projectArea" required>
                    <span>{{marketInfo.projectArea}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目所属部门" prop="projectDept" required>
                    <span>{{marketInfo.projectDept}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="业务类别" prop="projectContract">
                    <span>{{marketInfo.projectContract}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="客户简要介绍" prop="projectBackground">
                    <el-input v-model="marketInfo.projectBackground" type="textarea" :rows="3" :readonly="true"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="项目工作范围" prop="ProjectCondition">
                    <el-input v-model="marketInfo.ProjectCondition" type="textarea" :rows="3" :readonly="true"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item label="能力与业绩" prop="ContractorRequire">
                    <el-input v-model="marketInfo.ContractorRequire" type="textarea" :rows="3" :readonly="true"></el-input>
                  </el-form-item>
                </el-col>
                 <el-col :span="20">
                  <el-form-item label="意义及其他说明" prop="LocalSituation">
                    <el-input v-model="marketInfo.LocalSituation" type="textarea" :rows="3" :readonly="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <!-- 查询和重置按钮-->
          </div>
        </PageEditCollapse>
        <!-- 机会评审 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
          v-if="showModules[1] && marketInfo.estimateAmount-0>=200">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">机会评审</div>
          </div>
          <BlockLookEditToggle 
            ref="mrBlockToggle"
            :isDefaultActive="curEditIndex==1"
            v-loading="marketReviewLoading"
            :activeMouse="type==='edit'"
            @editClick="marketReviewEditClick"
            @mouseleave="marketReviewMouseleaveHandle"
            @cancelClick="marketReviewCancelClick"
            @saveClick="marketReviewSaveClick">
            <div slot="content">
              <!-- 高级搜索具体内容 -->
              <el-form
                :model="marketReview"
                label-position="right"
                label-width="150px"
                class="page-edit-colllapse-form"
                :rules="marketReviewRules"
                ref="marketReview">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="评审日期" prop="reviewDate">
                       <el-date-picker 
                         v-if="type==='edit'&&marketReviewEdit" 
                         v-model="marketReview.reviewDate" 
                         type="date" 
                         value-format="yyyy-MM-dd"
                         placeholder="选择日期">
                       </el-date-picker>
                      <span v-else>{{marketReview.reviewDate}}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="评审地点" prop="reviewAdress">
                      <el-input v-if="type==='edit'&&marketReviewEdit" v-model="marketReview.reviewAdress"></el-input>
                      <span v-else>{{marketReview.reviewAdress}}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="评审人员" prop="reviewPeopleListStr">
                       <PersonSelect 
                          v-if="type==='edit'&&marketReviewEdit"
                          :value="marketReview.reviewPeopleListStr" 
                          modal="false" 
                          v-bind:multiple="true" 
                          size=""
                          id="reviewPeople"
                          ref="reviewPeople">
                        </PersonSelect>
                      <span v-else>{{marketReview.reviewPeopleListStr}}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12" >
                    <el-form-item label="附加信息" prop="reviewAppendMessage">
                      <el-input v-if="type==='edit'&&marketReviewEdit"  v-model="marketReview.reviewAppendMessage"></el-input>
                      <span v-else>{{marketReview.reviewAppendMessage ? marketReview.reviewAppendMessage :'--'}}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="综合评审意见" prop="reviewComments">
                      <el-radio-group v-if="type==='edit'&&marketReviewEdit" v-model="marketReview.reviewComments">
                        <el-radio :label="1">通过</el-radio>
                        <el-radio :label="2">有条件通过</el-radio>
                        <el-radio style="color:#f00" :label="0">未通过</el-radio>
                      </el-radio-group>
                      <span v-else>{{reviewComments}}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="22" v-if="marketReview.reviewComments-0 !==1">
                    <el-form-item label="评审意见" prop="reviewCommentsNote">
                      <el-input v-if="type==='edit'&&marketReviewEdit" v-model="marketReview.reviewCommentsNote" type="textarea" :rows="3"></el-input>
                      <span v-else>{{marketReview.reviewCommentsNote}}</span>
                    </el-form-item>
                  </el-col>
                 </el-row>
                 <el-row>
                  <el-col :span="12" v-if="marketReview.reviewComments-0===2 || marketReview.reviewComments-0===1">
                    <el-form-item label="附件上传" prop="reviewFileId">
                       <FileUploadCommon 
                         v-if="type==='edit'&&marketReviewEdit" 
                         @uploadSuccess="uploadSuccess"
                         @uploadRemove="uploadRemove"
                         :fileList="marketReviewFileList"
                         :limit="1">
                        </FileUploadCommon>
                        <span v-else>{{marketReview.reviewFileName}}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
        <!-- 同心圆取号 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
          v-if="(showModules[2]&&marketInfo.estimateAmount-0>=200) || (showModules[1]&&marketInfo.estimateAmount-0<200)">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">关联项目（同心圆取号）</div>
          </div>
          <BlockLookEditToggle 
            ref="ofBlockToggle"
            :isDefaultActive="(marketInfo.estimateAmount-0>=200 && curEditIndex==2) || (marketInfo.estimateAmount-0<200 && curEditIndex==1)"
            v-loading="offerNumberLoading"
            :activeMouse="type==='edit'"
            @editClick="offerNumberEditClick"
            @mouseleave="offerNumberMouseleaveHandle"
            @cancelClick="offerNumberCancelClick"
            @saveClick="offerNumberSaveClick">
            <div slot="content">
              <!-- 高级搜索具体内容 -->
              <el-form
                :model="offerNumber"
                label-position="right"
                label-width="150px"
                class="page-edit-colllapse-form"
                :rules="offerNumberRules"
                ref="offerNumber">
                <el-row>
                 <el-col :span="24">
                   <el-row>
                     <el-col :span="8">
                      <el-form-item label="项目编码" prop="projectCode">
                        <div v-if="type==='edit'&&offerNumberEdit">
                          <el-input
                            :value="offerNumber.projectCode"
                            ref="input"
                            :readonly="true">
                           <el-button slot="append" icon="el-icon-plus"  class="btn-default" @click="showDialog"></el-button>
                          </el-input>
                        </div>
                        <span v-else>{{offerNumber.projectCode}}</span>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <router-link class="add" v-if="type==='edit'&&offerNumberEdit" :to="{path:'/run_project_add', query:{type:'offerNumber'} }">新增项目</router-link>
                    </el-col>
                  </el-row>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="项目名称" prop="projectName">
                      <span>{{offerNumber.projectName}}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
      </div>
    </PageTemplate>
    <!-- 选择项目弹窗 -->
    <el-dialog
      class="dialog"
      title="请选择"
      :visible.sync="showOfferNumberDialog"
       width="60%"
    >
       <el-form
        inline
        :model="query"
        ref="query"
        label-position="right"
        label-width="82px"
        class="search-collapse-pro-form">
          <SearchCollapsePro :isAdvSearch="false">
              <div slot="title" class="search-collapse-pro-title">
                <el-form-item label-width="0px">
                  <el-input v-model="query.searchKey" placeholder="项目编码/项目名称">
                    <el-button slot="append" icon="el-icon-search" @click="queryDataTableLike"></el-button>
                  </el-input>
                </el-form-item>
              </div>
            </SearchCollapsePro>
        </el-form>
        <el-table
          class="table"
          border
          ref="multipleTable"
          :data="tables"
          tooltip-effect="dark"
          style="width: 100%"
          :show-overflow-tooltip="true"
          @selection-change="handleSelectionChange"
          :header-cell-style="{background:tableHeaderBGC}"
        >
          <!-- <el-table-column align="center" type="selection" width="60"></el-table-column> -->
          <el-table-column align="center" width="60">
            <template slot-scope="scope">
               <el-radio v-model="tableSelectId" :label="scope.row.id"  @change.native="getCurrentRow(scope.row)">&nbsp;</el-radio>
            </template>
          </el-table-column>
          <!-- <el-table-column type="index" :label="$t('cm.no')" align="center" width="60" fixed></el-table-column> -->
          <el-table-column prop="projectCode" label="项目编码" align="center" width="200"></el-table-column>
          <el-table-column prop="projectName" label="项目名称" align="center" width="200"></el-table-column>
          <el-table-column prop="marketCustomerName" label="客户名称" align="center" width="200"></el-table-column>
          <!-- <el-table-column prop="contractCode" label="合同编码" align="center" width="200"></el-table-column>
          <el-table-column prop="contractName" label="合同名称" align="center" width="200"></el-table-column>
          <el-table-column prop="leadingManName" label="承揽负责人" align="center" width="200"></el-table-column>
          <el-table-column prop="projectManagerName" label="项目经理" align="center" width="200"></el-table-column>
          <el-table-column prop="projectStageName" label="项目阶段" align="center" width="200"></el-table-column> -->
          <!-- <el-table-column prop="marketInfoName" label="市场机会" align="center" width="200"></el-table-column> -->
          <el-table-column prop="messageFunds" label="信息来源" align="center" width="200"></el-table-column>
        </el-table>
        <div class="block pager-customer">
          <el-pagination
            background
            layout="total, slot, prev"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
            <el-button
              ref="firstPage"
              @click="firstPage"
              class="first-page"
              :disabled="firstPageDisabled"
            >{{$t('cm.firstPage')}}</el-button>
          </el-pagination>
          <el-pagination
            background
            layout="pager, next, slot, jumper"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
            <el-button
              ref="lastPage"
              @click="lastPage"
              class="last-pager"
              :disabled="lastPageDisabled"
            >{{$t('cm.lastPage')}}</el-button>
          </el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogCancel">取 消</el-button>
          <el-button type="primary" @click="dialogConfirm">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState,mapActions } from 'vuex'
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import PageTemplate from '@/components/common/PageTemplate'
import PageEditCollapse from '@/components/common/PageEditCollapse'
import TitleBack from '@/components/common/TitleBack'
import BlockLookEditToggle from '@/components/common/BlockLookEditToggle'
import HasBtn from '@/mixins/HasBtn'
import {COMMON} from '@/utils/commonUtil'
import opr_management from '@/api/opr_management'
import Pagination from '@/mixins/Pagination'
import SearchCollapsePro from '@/components/common/SearchCollapsePro'
import PersonSelect from '@/components/asc/PersonSelect'
import FileUploadCommon from '@/components/common/FileUploadCommon'
var reviewComments ={
  0:"未通过",
  1:"通过",
  2:"有条件通过"
};
export default {
  components: {
    PageTemplate, 
    PageEditCollapse, 
    TitleBack, 
    BlockLookEditToggle,
    SearchCollapsePro,
    PersonSelect,
    FileUploadCommon
  },
  props: {
    // look：查看；edit：编辑
    type: {
      type: String,
      default: "look"
    },
  },
  mixins: [Pagination, HasBtn],
  data () {
    return {
      title:"市场机会详情",
      //当前默认显示为编辑状态的模块index
      curEditIndex:null,
      //接口返回的全部信息合集
      marketDetail:{},
      //模块是否显示
      showModules:[],
      marketInfo: {
        marketName:null,
        customerName:null,
        projectType:null,
        customerType:null,
        estimateAmount:null,
        informationValid:null,
        projectAddress:null,
        sourceFunds:null,
        projectContract:null,
        projectSetting:null,
        projectStatus:null,
      },
      marketReviewBack:{},//编辑时的备份
      marketReview: {
        reviewDate:null,
        reviewAdress:null,
        reviewPeopleList:null,
        reviewComments:null,
        reviewCommentsNote:null, //综合评审意见：2：有条件通过
        reviewAppendMessage:null, //附件信息
      },
      rules:[{ required: true, message: '必填项',trigger: 'blur'}],
      marketReviewRules: {},
      baseMarketReviewRules: {
        reviewDate: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        reviewAdress: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        reviewPeopleListStr: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        reviewComments: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
      },
      reviewCommentsNote: [
          { required: true, message: '必填项', trigger: 'blur' }
      ],
      offerNumber:{
        projectId:null,
        projectName:null,
        projectCode: null,
      },
      offerNumberRules:{
        projectCode: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
      },
      marketReviewEdit:false,//机会评审是否为编辑模式
      marketReviewLoading:false,//机会评审loading
      offerNumberLoading:false,//同心圆取号loading
      offerNumberEdit:false,//同心圆取号是否为编辑模式
      // showOfferNumber:true,//是否显示同心圆取号模块

      tables:[],
      showOfferNumberDialog:false,
      query:{
         searchKey:null,
         hasMarketInfo:"0",
      },
      tableSelect: null,
      tableSelectId: null,
      marketReviewFileList:[],
    }
  },
  watch: {
    marketDetail:{
      handler:function(val){
        const { 
          marketInfo,
          marketReview,
          projectInfo,
        } = val;
        let showMarketInfo = marketInfo ? true :false;
        let showMarketReview = marketReview&&marketReview.reviewComments-0 !=0 ? true :false;;
        let showOfferNumber = projectInfo  ? true :false;
        let arr = [];
        if(marketInfo.estimateAmount-0>=200){
           arr = [showMarketInfo,showMarketReview,showOfferNumber];
        }else{
           arr = [showMarketInfo,showOfferNumber];
        }
        this.showModules = this.showModulesFn(arr,this.type);
        switch(this.curEditIndex){
            case 1 :
              if(marketInfo.estimateAmount-0>=200){
                if(!marketReview){
                  this.marketReviewEdit = true;
                }else{
                  if(marketReview.reviewComments !=0){
                      this.marketReviewEdit = true;
                    }else{
                      this.curEditIndex = null
                    }
                }
              }else{
                this.offerNumberEdit = true;
              }
              break; 
            case 2 :
              this.offerNumberEdit = true;
              break; 
            case null :
              if(this.projectItem){
                // this.$refs.ofBlockToggle.editClick()
                this.curEditIndex = marketInfo.estimateAmount-0>=200 ? 2 :1
                this.offerNumberEdit = true;
              }
              break; 
        }
      },
      deep:true,
    }, 
    "marketReview.reviewComments"(value) {
      // 0:"未通过",
      // 1:"通过",
      // 2:"有条件通过"
      switch(value){
        case 0:
          this.marketReviewRules = JSON.parse(JSON.stringify(this.baseMarketReviewRules));
          break;
        case 1:
           this.marketReviewRules = JSON.parse(JSON.stringify(this.baseMarketReviewRules));
        break;
        case 2:
           this.marketReviewRules = Object.assign({},this.baseMarketReviewRules,{reviewCommentsNote:this.reviewCommentsNote});
        break;
      }
      
    },
    "marketInfo.estimateAmount"(value) {
      if(value-0>=200){
        this.marketReviewRules = JSON.parse(JSON.stringify(this.baseMarketReviewRules));
      }else{
        this.marketReviewRules = {};
      }
    },
    projectItem:{
      handler:function(val){
        if(!val) return;
        const {id,projectName,projectCode} = val;
        this.offerNumber = {
          projectId: id,
          projectName,
          projectCode,
        };
      },
      deep:true,
      immediate:true
      
    },
    "marketReview.reviewPeopleList"(val) {
       if(val.length ==0 ) return;
      this.$set(this.marketReview,"reviewPeopleListStr",COMMON.arrToStr(val,"peopleName"))
    },
  },
 
  computed: {
     ...mapState({
      tableHeaderBGC: state => state.common.tableHeaderBGC,
      projectItem: state => state.common.projectItem,
    }),
    reviewComments() { 
      return reviewComments[this.marketReview.reviewComments]
    },
    
  },
  created () {
    this.getInitData();

    //获取列表数据
    this.getAllDataTable();
  },
  methods: {
    ...mapActions('common', [
      'saveProjectItem',
    ]),
    getInitData(){
       opr_management.getMarketInfoById({
         id:this.$router.history.current.params.id
       }, result => {
         if (result.code === Constant.RT_SUCCESS) {
             const { 
             marketInfo,
             marketReview,
             projectInfo
             } = result.data;
             this.marketDetail = JSON.parse(JSON.stringify(result.data));
            if(marketInfo)  this.marketInfo =  marketInfo;
            if(marketReview)  this.marketReview = marketReview;
            if(projectInfo && !this.projectItem)  this.offerNumber = projectInfo;
             //已有附件
            if(marketReview&&marketReview.reviewFileId){
             this.marketReviewFileList =[
                {
                  name:marketReview.reviewFileName,
                  id:marketReview.reviewFileId
                }
              ]
            }
        } else {
          ALERT.error(result.msg)
        }
        
      })

    },

    uploadSuccess (res, fileKey) {
      if (res.data && res.data[0]) {
        this.marketReview.reviewFileId = res.data[0].fileId
        let file = {name: res.data[0].fileName, url: res.data[0].url, id: res.data[0].fileId}
        this.marketReviewFileList.push(file)
      }
    },
    uploadRemove (fileList, fileKey) {
      let resList = fileList.map(item => {
        return {
          name: item.name,
          url: item.url,
          id: item.fileId
        }
      })
      this.marketReviewFileList = resList
      this.marketReview.reviewFileId = resList.map(item=>item.id).join(",");
    },
    //判断模块是否显示 
    showModulesFn(arr,type){
     let newArr =[];
     let flag = true; 
     for(let i = 0;i<arr.length;i++){
       let bol = true;
       let tmmpArr = arr.slice(0,i+1);
       for(let item of arr.slice(0,i+1)){
         if(bol==true&&!!item == false&&flag&&type=='edit'){
           bol = true;
           flag = false;
           this.curEditIndex = i;
         }else{
           bol = bol && item
         }
       }
       if(i == arr.length-1 && flag){
         this.curEditIndex = null;
       }
       newArr[i] = bol
     }
     return newArr
    },
    //取消所有编辑状态
    inactiveAll(refs){
      let refsArr =['mrBlockToggle','ofBlockToggle'];
      refsArr.forEach(element => {
        if(refs!=element &&  this.$refs[element]) {
          this.$refs[element].cancelClick();
        }
      });
      this.curEditIndex = null;
    },
    //机会评审编辑操作相关方法
    marketReviewEditClick(){
      this.inactiveAll("mrBlockToggle");
      this.marketReviewEdit = true;
    },
    marketReviewMouseleaveHandle({showBtn}){
      this.marketReviewEdit = showBtn;
    },
    marketReviewCancelClick(){
      this.marketReviewEdit = false;
      this.$refs.marketReview.clearValidate();
      this.marketReview = this.marketDetail.marketReview ? JSON.parse(JSON.stringify(this.marketDetail.marketReview)) : {}
    },
   
    // 保存
    marketReviewSaveClick(){
      this.marketReview.reviewPeopleList = COMMON.changePersonSelectData(this.$refs.reviewPeople);
      this.$set(this.marketReview,"reviewPeopleListStr",COMMON.arrToStr(this.marketReview.reviewPeopleList,"peopleName"))
      this.$refs.marketReview.validate((valid, error) => {
        if (valid) {
          this.marketReviewLoading = true;
          const {
            reviewComments, // 综合评审意见：0；未通过，1：通过 2：有条件通过
            reviewPeopleList, //评审人员
            reviewAdress, //评审地点
            reviewDate, // 评审时间
            reviewCommentsNote, //综合评审意见：2：有条件通过
            reviewAppendMessage, //附加信息
            reviewFileId,
          } = this.marketReview;
          opr_management.saveOrUpdateReview({
            marketinfoId:this.$router.history.current.params.id,
            reviewComments,
            reviewPeopleList,
            reviewAdress,
            reviewDate,
            reviewCommentsNote,
            reviewAppendMessage,
            reviewFileId
          }, result => {
            this.marketReviewLoading = false;
            if (result.code === Constant.RT_SUCCESS) {
                this.marketReviewEdit = false;
                this.showOfferNumber = true;
                this.$refs.mrBlockToggle.inactive();
                this.getInitData();
            } else {
              ALERT.error(result.msg)
            }
          })

        }
      });
      

    },
    //同心圆编辑操作相关方法
    offerNumberEditClick(){
      this.inactiveAll("ofBlockToggle");
      this.offerNumberEdit = true;
    },
    offerNumberMouseleaveHandle({showBtn}){
      this.offerNumberEdit = showBtn;
    },
    offerNumberCancelClick(){
      this.offerNumberEdit = false
      this.offerNumber = this.marketDetail.projectInfo ? JSON.parse(JSON.stringify(this.marketDetail.projectInfo)) : {}
    },
    offerNumberSaveClick(){
      this.$refs.offerNumber.validate((valid, error) => {
        if (valid) {
          this.offerNumberLoading = true;
          const {
            projectId, 
            // projectName, 
          } = this.offerNumber;
          opr_management.offerNumber({
            marketInfoId:this.$router.history.current.params.id,
            projectId,
            // projectName
          }, result => {
            this.offerNumberLoading = false;
            if (result.code === Constant.RT_SUCCESS) {
                this.offerNumberEdit = false;
                this.$refs.ofBlockToggle.inactive();
                this.getInitData();
                this.saveProjectItem(null);
            } else {
              ALERT.error(result.msg)
            }
          })

        }

      })

    },

    //显示同心圆取号弹窗
    showDialog(){
      this.showOfferNumberDialog = true
    },
    //弹窗确认
    dialogConfirm(){
      this.showOfferNumberDialog = false;
      const { id,projectName,projectCode } = this.tableSelect
      this.offerNumber.projectId = id;
      this.offerNumber.projectName = projectName ;
      this.offerNumber.projectCode = projectCode ;
    },
    //弹窗取消
    dialogCancel(){
      this.showOfferNumberDialog = false;
      this.tableSelect = null;
      this.tableSelectId = null;
    },
    //获取选中数据
    getCurrentRow(row){    
      this.tableSelect = row;
      this.tableSelectId = row.id;
    },

    queryDataTableLike () {
      this.getAllDataTable();
    },
    //获取列表数据
    getAllDataTable () {
      this.queryTableList({
        ...this.query,
        pageNum: this.pagingCurrentPageNum,
        pageSize: this.pagingPageSize
      })
    },
    //统一与后台操作的方法
    queryTableList (params) {
      //这里的params是对象
      //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
      let _this = this 
      let tables = [] 
      let totalCount = 0 
      opr_management.getProjectList(params, result => {
        if (result.code === Constant.RT_SUCCESS) {
          //表格数据  数组            
          tables = result.data.results
          //分页数据
          totalCount = result.data.totalRows
        } else {
          // _this.$t('cm.tips')
          ALERT.error(result.data.msg)
        }
        _this.setPagingTotal(totalCount)
        this.tables = tables
      })
    },
   
  },
  destroyed(){
    this.saveProjectItem(null);
  }
}
</script>

<style lang="scss">
.market-detail{
  .el-form-item__content>span:empty:before{
    content:"--"
  }
  .form-input{
    width: 80% !important;
  }
  .add{
    color: #004a86;
    text-decoration: underline;
    line-height: 40px;
    padding-left: 30px;
  }
}
</style>
